package com.ccp.dev.qbdms.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.page.PageBean;
import com.ccp.dev.core.basic.response.ReturnCode;
import com.ccp.dev.core.basic.util.ContextUtil;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.poi.excel.Excel;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.core.util.DateUtil;
import com.ccp.dev.core.util.StringPool;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.extend.model.ExtendSysFile;
import com.ccp.dev.qbdms.consts.HighlightConst;
import com.ccp.dev.qbdms.consts.ZhiLiangConst;
import com.ccp.dev.qbdms.dao.WQbdQualityKnowDao;
import com.ccp.dev.qbdms.model.SysOrgDeploy;
import com.ccp.dev.qbdms.model.WQbdQualityKnow;
import com.ccp.dev.qbdms.model.WQbdSoftwareView;
import com.ccp.dev.qbdms.model.WQbdSoftwareproAnls;
import com.ccp.dev.qbdms.repository.WQbdQualityKnowRepository;
import com.ccp.dev.qbdms.util.BaseUtil;
import com.ccp.dev.qbdms.util.HttpSendUtil;
import com.ccp.dev.qbdms.util.ReadAttachmentUtil;
import com.ccp.dev.qbdms.util.TikaUtils;
import com.ccp.dev.system.model.SysFile;
import com.ccp.dev.system.service.DictionaryService;
import com.ccp.dev.system.service.SysFileService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.SearchResultMapper;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;

import static com.ccp.dev.extend.util.ServiceUtil.getBasePath;
import static com.ccp.dev.qbdms.consts.ZhiLiangConst.HAIR_DOWN_MAP;
import static com.ccp.dev.qbdms.util.TikaUtils.replaceBlank;


/**
 * 质量知识 信息操作服务类
 *
 * @author 于金
 * @date 2020-07-20 10:41:54
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WQbdQualityKnowService extends BaseService<WQbdQualityKnow> {

    @Resource
    private WQbdQualityKnowDao dao;
    @Resource
    private WQbdQualityKnowRepository wQbdQualityKnowRepository;

    @Resource
    SysFileService sysFileService;
    @Resource
    DictionaryService dictionaryService;
    @Autowired
    ElasticsearchTemplate elasticsearchTemplate;


    public HSSFWorkbook exportExcel(Excel excel,QueryFilter queryFilter){
    List<WQbdQualityKnow> dataList = this.dao.queryAll(queryFilter);
        int startRow = 1;
        //给每一个单元格赋值
        for (WQbdQualityKnow data : dataList) {
        excel.cell(startRow, 0).value(data.getId());
        //excel.cell(startRow, 1).value(data.getMc());
        //可在赋值时，根据需求进行格式化
        //excel.cell(startRow, 2).value(DateFormatUtil.formatDate(data.getRq()));
        //excel.cell(startRow, 3).value(data.getSj());
        //excel.cell(startRow, 4).value(data.getTenantId());
        startRow++;
        }
        return excel.getWorkBook();
    }
//------------------------------------------es接口------------------------------------------------------------------------
    /**
     * 保存
     * @param
     */
    public  void  addAndupdate(WQbdQualityKnow wQbdQualityKnow){
        String attachmentUrl = wQbdQualityKnow.getEnclosure();
        Optional<WQbdQualityKnow> repository = wQbdQualityKnowRepository.findById(wQbdQualityKnow.getId());
        //新增
        if( ObjectUtils.isEmpty(repository)){
            if (StringUtil.isNotEmpty(attachmentUrl)){
                List<Map<String, String>> listObjectFir = (List<Map<String, String>>) JSONArray.parse(attachmentUrl);
                WQbdQualityKnow wQbdQualityKnow1 = getFile(listObjectFir, wQbdQualityKnow);
                wQbdQualityKnowRepository.save(wQbdQualityKnow1);
            }
        }else {
            if (StringUtil.isNotEmpty(attachmentUrl)){
                List<Map<String, String>> listObjectFir = (List<Map<String, String>>) JSONArray.parse(attachmentUrl);
                WQbdQualityKnow wQbdQualityKnow1 = getFile(listObjectFir,wQbdQualityKnow);
                wQbdQualityKnowRepository.save(wQbdQualityKnow1);
            }

        }
    }

    /**
     * 把附件内容在封装一遍 ，编辑的时候也要 封装不封装为null 则ES库中也会更新为null 不能更新部分字段 只能全部
     * @param list
     * @param wQbdQualityKnow
     * @return
     */
    public  WQbdQualityKnow  getFile(List<Map<String, String>> list,WQbdQualityKnow wQbdQualityKnow){
        String fileNames="";
        String texts="";
        String basePath = getBasePath();
        for (Map<String, String> stringStringMap : list) {
            String fileName =stringStringMap.get("fileName");
            SysFile sysFile = sysFileService.getOneById(stringStringMap.get("fileId"));
            if (BeanUtils.isNotEmpty(sysFile)) {
                fileNames+=fileName;
                String path = basePath + File.separator + sysFile.getFilePath();
                String text = TikaUtils.fileToString(path);
                texts+=text;
            }
        }
        wQbdQualityKnow.setEnclosureFileName(fileNames);
//        wQbdQualityKnow.setEnclosureContent(replaceBlank(texts));
        wQbdQualityKnow.setEnclosureContent(texts);
        return  wQbdQualityKnow;
    }

    public WQbdQualityKnow queryES(String id){
        return null;
    }


    /**
     * 高级检索
     * @param queryFilter
     * @return
     */
    public List<WQbdQualityKnow> queryES(QueryFilter queryFilter){
        Object dicId=queryFilter.get("dicId");
        String secret=queryFilter.get("secret").toString();
        String belongdeptname=queryFilter.get("belongdeptname").toString().replace("%","").substring(0,5);
        String belongdeptname1=BaseUtil.getCurrentOrgCode();
        Object filldeptid = queryFilter.get("filldeptid");
        Object knowedgeClass=queryFilter.get("knowedgeClass");
        Object fillmanaccount = queryFilter.get("fillmanaccount");
        Object mj = queryFilter.get("mj");
        Object year = queryFilter.get("year");

        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        BoolQueryBuilder boolQueryBuilder_fl = QueryBuilders.boolQuery();

        if(!ObjectUtils.isEmpty(year)){
            Date st =   DateUtil.getYearFirst(Integer.valueOf(year.toString()));
            Date end=   DateUtil.getYearLast(Integer.valueOf(year.toString()));
            boolQueryBuilder.must(QueryBuilders.rangeQuery("createTime").from(st.getTime()).to(end.getTime()).includeUpper(false).includeLower(false))  ;
        }
        //用户账号
        if(!ObjectUtils.isEmpty(fillmanaccount)){
            fillmanaccount=fillmanaccount.toString();
            boolQueryBuilder.must( QueryBuilders.termQuery("fillmanaccount",fillmanaccount));
        }

        NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
        if (!ObjectUtils.isEmpty(dicId)){
            TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("knowledgeClassification.keyword",dicId);
            boolQueryBuilder_fl.should(termQueryBuilder);
            TermQueryBuilder termQueryBuilder1 = QueryBuilders.termQuery("knowledgeClassification2.keyword",dicId);
            boolQueryBuilder_fl.should(termQueryBuilder1);


        }


        if(!ObjectUtils.isEmpty("knowedgeClass")){

            List<String> result = new ArrayList<>();
            if (knowedgeClass instanceof ArrayList<?>) {
                for (Object o : (List<?>) knowedgeClass) {
                    result.add(String.class.cast(o));
                }
            }
            for (int i=0;i<result.size();i++){
                String dicIds=result.get(i).toString();
                TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("knowledgeClassification.keyword",dicIds);
                boolQueryBuilder_fl.should(termQueryBuilder);
            }


        }

        if(!ObjectUtils.isEmpty(filldeptid)){
            String filldeptids = filldeptid.toString();
            TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("departCode", filldeptids);
            boolQueryBuilder.must(termQueryBuilder);
        }
        Object filldeptHospitalId= queryFilter.get("filldeptHospitalId");
        if(!ObjectUtils.isEmpty(filldeptHospitalId)){
            String filldeptHospitalIds = filldeptHospitalId.toString();
            TermQueryBuilder termQuery = QueryBuilders.termQuery("filldeptHospitalId", filldeptHospitalIds);
            boolQueryBuilder.must(termQuery);
        }

        //模糊查询
//        QueryBuilder queryBuilder = QueryBuilders.wildcardQuery("belongdeptname.keyword", belongdeptname+"*");
          BoolQueryBuilder boolQueryBuilder_deptName = QueryBuilders.boolQuery();
          QueryBuilder queryBuilder = QueryBuilders.termQuery("belongdeptname.keyword", belongdeptname);
          QueryBuilder queryBuilder1 = QueryBuilders.termQuery("belongdeptname.keyword", belongdeptname1);
          boolQueryBuilder_deptName.should(queryBuilder).should(queryBuilder1);
        Object content1 = queryFilter.get("content");
        if (null!=content1){
            String content=queryFilter.get("content").toString();
            QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(content).analyzer("ik_smart");
            boolQueryBuilder.must(boolQueryBuilder_deptName).must(queryStringQueryBuilder);

        }
        else{
//            boolQueryBuilder.must(queryBuilder);
            boolQueryBuilder.must(boolQueryBuilder_deptName);
        }



        //小于等于
        boolQueryBuilder.must(QueryBuilders.rangeQuery("secret").lte(secret));
        if(!ObjectUtils.isEmpty(mj)){
            boolQueryBuilder.must(QueryBuilders.termQuery("secret",mj));
        }
        nativeSearchQueryBuilder.withQuery(boolQueryBuilder.must(boolQueryBuilder_fl));
        nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC));
        System.err.println(queryFilter.getPageBean().getCurrentPage());
        System.err.println(queryFilter.getPageBean().getPageSize());
        PageRequest pageRequest = PageRequest.of(queryFilter.getPageBean().getCurrentPage()-1, queryFilter.getPageBean().getPageSize());
//        PageRequest pageRequest = PageRequest.of(0,1000);
         //高亮
        nativeSearchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("enclosureContent").preTags(HighlightConst.preTag).postTags(HighlightConst.postTag).fragmentSize(100).numOfFragments(3),
                new HighlightBuilder.Field("knowledgeName").preTags(HighlightConst.preTag).postTags(HighlightConst.postTag).fragmentSize(100).numOfFragments(3));
//        nativeSearchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("enclosureFileName").preTags(HighlightConst.preTag).postTags(HighlightConst.postTag).fragmentSize(100).numOfFragments(3));
        System.err.println(nativeSearchQueryBuilder.build().getQuery().toString());
        nativeSearchQueryBuilder.withPageable(pageRequest);
        long count = elasticsearchTemplate.count(nativeSearchQueryBuilder.build(), WQbdQualityKnow.class);
        PageBean pageBean = queryFilter.getPageBean();
        pageBean.setTotalCount((int) count);
        List<WQbdQualityKnow> wQbdQualityKnows = elasticsearchTemplate.queryForList(nativeSearchQueryBuilder.build(), WQbdQualityKnow.class);
        AggregatedPage<WQbdQualityKnow> page = elasticsearchTemplate.queryForPage(nativeSearchQueryBuilder.build(), WQbdQualityKnow.class,
                new SearchResultMapper() {
                    @Override
                    public <T> AggregatedPage<T> mapResults(SearchResponse searchResponse, Class<T> aClass, Pageable pageable) {
                        List<WQbdQualityKnow> list = new ArrayList<>();
                        for (SearchHit searchHit : searchResponse.getHits()) {
                            WQbdQualityKnow wQbdQualityKnow = com.alibaba.fastjson.JSONObject.parseObject(com.alibaba.fastjson.JSONObject.toJSONString(searchHit.getSourceAsMap()), WQbdQualityKnow.class);
                            if (searchResponse.getHits().getHits().length <= 0) {
                                return null;
                            }
                            HighlightField title = searchHit.getHighlightFields().get("enclosureContent");
                            if (title != null) {
                                wQbdQualityKnow.setEnclosureContent(title.fragments()[0].toString());
                            }
                            HighlightField knowledgeName = searchHit.getHighlightFields().get("knowledgeName");
                            if (knowledgeName != null) {
                                wQbdQualityKnow.setKnowledgeName(knowledgeName.fragments()[0].toString());
                            }
                            list.add(wQbdQualityKnow);
                        }
                        if (list.size() > 0) {
                            return new AggregatedPageImpl<>((List<T>) list);
                        }
                        return null;
                    }
                });

//        Page<WQbdQualityKnow> list = wQbdQualityKnowRepository.search(nativeSearchQueryBuilder.build());


        if (null==page){
            return null;
        }
        List<WQbdQualityKnow> list = page.getContent();
        return list;
    }


    public int queryESCount(QueryFilter queryFilter){
        Object dicId=queryFilter.get("dicId");
        String secret=queryFilter.get("secret").toString();
        String belongdeptname=queryFilter.get("belongdeptname").toString().replace("%","");
        Object filldeptid = queryFilter.get("filldeptid");
        Object knowedgeClass=queryFilter.get("knowedgeClass");
        NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        BoolQueryBuilder boolQueryBuilder_fl = QueryBuilders.boolQuery();
        if (!ObjectUtils.isEmpty(dicId)){
            TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("knowledgeClassification.keyword",dicId);
            boolQueryBuilder_fl.should(termQueryBuilder);
            TermQueryBuilder termQueryBuilder1 = QueryBuilders.termQuery("knowledgeClassification2.keyword",dicId);
            boolQueryBuilder_fl.should(termQueryBuilder1);


        }
        if(!ObjectUtils.isEmpty("knowedgeClass")){

            List<String> result = new ArrayList<>();
            if (knowedgeClass instanceof ArrayList<?>) {
                for (Object o : (List<?>) knowedgeClass) {
                    result.add(String.class.cast(o));
                }
            }
            for (int i=0;i<result.size();i++){
                String dicIds=result.get(i).toString();
                TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("knowledgeClassification.keyword",dicIds);
                boolQueryBuilder_fl.should(termQueryBuilder);
            }


        }

        if(!ObjectUtils.isEmpty(filldeptid)){
            String filldeptids = filldeptid.toString();
            TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("filldeptid", filldeptids);
            boolQueryBuilder.must(termQueryBuilder);
        }
        Object filldeptHospitalId= queryFilter.get("filldeptHospitalId");
        if(!ObjectUtils.isEmpty(filldeptHospitalId)){
            String filldeptHospitalIds = filldeptHospitalId.toString();
            TermQueryBuilder termQuery = QueryBuilders.termQuery("filldeptHospitalId", filldeptHospitalIds);
            boolQueryBuilder.must(termQuery);
        }

        //模糊查询
//        QueryBuilder queryBuilder = QueryBuilders.wildcardQuery("belongdeptname.keyword", belongdeptname+"*");
        QueryBuilder queryBuilder = QueryBuilders.termQuery("belongdeptname.keyword", belongdeptname);

        Object content1 = queryFilter.get("content");
        if (null!=content1){
            String content=queryFilter.get("content").toString();
            QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(content).analyzer("ik_smart");
            boolQueryBuilder.must(queryBuilder).must(queryStringQueryBuilder);

        }
        else{
            boolQueryBuilder.must(queryBuilder);
        }

        //小于等于
        boolQueryBuilder.must(QueryBuilders.rangeQuery("secret").lte(secret));
        nativeSearchQueryBuilder.withQuery(boolQueryBuilder.must(boolQueryBuilder_fl));
        nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC));
        System.err.println(queryFilter.getPageBean().getCurrentPage());
        System.err.println(queryFilter.getPageBean().getPageSize());
        PageRequest pageRequest = PageRequest.of(queryFilter.getPageBean().getCurrentPage()-1, queryFilter.getPageBean().getPageSize());
//        PageRequest pageRequest = PageRequest.of(0,1000);
        //高亮
        nativeSearchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("enclosureContent").preTags(HighlightConst.preTag).postTags(HighlightConst.postTag).fragmentSize(100).numOfFragments(3));
        System.err.println(nativeSearchQueryBuilder.build().getQuery().toString());
        nativeSearchQueryBuilder.withPageable(pageRequest);
        long count = elasticsearchTemplate.count(nativeSearchQueryBuilder.build(), WQbdQualityKnow.class);
        return (int) count;
    }





    public long getLastUpdateTime() {
        WQbdQualityKnow lastUpdateTime = dao.getLastUpdateTime();
        return lastUpdateTime.getUpdateTime().getTime();
    }

    public List<String> getWords() {
        return dao.getWords();
    }


    public void delete(String id){
         wQbdQualityKnowRepository.deleteById(id);
    }

    public List<WQbdQualityKnow> queryUnread(QueryFilter queryFilter){
        queryFilter.addFilter("userId", ContextUtil.getCurrentUser().getUserId());
        return this.dao.queryUnread(queryFilter);
    }

    /**
     * 保存接口传输的数据
     *
     * @param datalist 主表model,有子表的包含子表数据
     * @return
     */
    public int saveAll(List<WQbdQualityKnow> datalist,List<ExtendSysFile> extendSysFileList) {
        ReadAttachmentUtil.getEntityData(datalist,extendSysFileList);
        List<WQbdQualityKnow> wQbdQualityKnows = new ArrayList<>();
        for(WQbdQualityKnow wQbdQualityKnow : datalist){
            if(StringUtil.isEmpty(wQbdQualityKnow.getFilldeptHospitalId())){
                wQbdQualityKnow.setBelongdeptname(BaseUtil.getCurrentTenOrgCodePath(wQbdQualityKnow.getFilldeptid()));
            }else{
                wQbdQualityKnow.setBelongdeptname(BaseUtil.getCurrentTenOrgCodePath(wQbdQualityKnow.getFilldeptHospitalId()));
            }
            // 直接插主表数据
            wQbdQualityKnows.add(wQbdQualityKnow);
        }
        return super.addList(wQbdQualityKnows);
    }

    /**
     * 根据主表id查询主表加子表数据
     *
     * @param id 主表id
     * @return
     */
    public WQbdSoftwareproAnls getParentAndChilden(String id) {
        return dao.getParentAndChilden(id);
    }



    @Resource
    SysOrgDeployService sysOrgDeployService;
    /**
     * 质量知识下发接口
     * @param updateList
     * @return
     */
    public boolean reportSend(List<WQbdQualityKnow> updateList) {

        boolean status=true;
        List<SysOrgDeploy> sysOrgDeployList = sysOrgDeployService.getAllSonDeployMethod();
        List<SysOrgDeploy> failOrgs=new ArrayList<>(sysOrgDeployList.size());
        for (SysOrgDeploy org : sysOrgDeployList) {
            if (org.getOrgCode()!=null &&!ZhiLiangConst.DEPMETHOND_CENTER.equals(org.getDepmethod())){
                //分级部署 调用接口
                String code=org.getOrgCode()+StringPool.DOT;
                String url = org.getUrl();
                url = url + ZhiLiangConst.URL_API + ZhiLiangConst.URL_VERSION + "wQbdQualityKnow/reportSend";
                Map<String, Object> map = new HashMap<>(2);
                map.put(ZhiLiangConst.API_REPORT_PARA_LIST, updateList);
                map.put("orgCode",code);

                List<ExtendSysFile> extendSysFileList = ReadAttachmentUtil.getReport(map, "WQbdQualityKnow");
                if(BeanUtils.isNotEmpty(extendSysFileList)){
                    map.put(ZhiLiangConst.API_REPORT_PARA_LIST_FILE, extendSysFileList);
                }
                try {
                    ResponseEntity<JSONObject> response = HttpSendUtil.httpRestClient(url, HttpMethod.POST, map);
                    if (response.getStatusCode() != HttpStatus.OK || (int) response.getBody().get("code") != ReturnCode.SUCCESS.getCode()) {
                        updateList(updateList, HAIR_DOWN_MAP.get( ZhiLiangConst.GROUP_FAILURE_SEND2));
                        failOrgs.add(org);
                        status=false;
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    updateList(updateList,  HAIR_DOWN_MAP.get( ZhiLiangConst.GROUP_FAILURE_SEND2));
                    failOrgs.add(org);
                    status=false;
                }
            }else{
//                 集中部署
                String code= BaseUtil.getCurrentTenOrgCodePath()+org.getOrgCode()+StringPool.DOT;
                List<WQbdQualityKnow> list=new ArrayList<>();
                for(WQbdQualityKnow wQbdQualityKnow:updateList){
                    WQbdQualityKnow wQbdQualityKnow_new=new WQbdQualityKnow();
                    BeanUtils.copyNotNullProperties(wQbdQualityKnow_new,wQbdQualityKnow);
                    try{
                        WQbdQualityKnow qualityKnow = dao.getOneByOldId(wQbdQualityKnow.getId(),code);
                        if(BeanUtils.isNotEmpty(qualityKnow)){
                            dao.delByOldId(qualityKnow.getOldId(),code);
                        }
                        System.err.println(wQbdQualityKnow.getId());
                        wQbdQualityKnow_new.setOldId(wQbdQualityKnow.getId());
                        wQbdQualityKnow_new.setId(UUIDUtils.getUUIDFor32());
                        wQbdQualityKnow_new.setBelongdeptname(code);
                        wQbdQualityKnow_new.setStatus(HAIR_DOWN_MAP.get( ZhiLiangConst.GROUP_PREPARE_SEND));
                        list.add(wQbdQualityKnow_new);
//                        保存ES数据
                        addAndupdate(wQbdQualityKnow_new);
                    }catch (Exception e){
                        status=false;
                        e.printStackTrace();
                    }
                }
                dao.addList(list);
            }
        }
        updateList(updateList,  HAIR_DOWN_MAP.get( ZhiLiangConst.GROUP_ALREADY_SEND3));
        return status;
    }



    public int updateList(List<WQbdQualityKnow> updateList,String status) {
        int result=0;
        for(WQbdQualityKnow updateEntity:updateList){
            if(status!=null){updateEntity.setStatus(status);}
            result+=update(updateEntity);
        }
        return result;
    }

    /**
     * 保存es和oracle 数据
     * @param list
     * @param orgCode
     * @return
     */
    public int saveSendReport(List<WQbdQualityKnow> list,String orgCode) {
        for (WQbdQualityKnow wQbdQualityKnow:list){
            wQbdQualityKnow.setBelongdeptname(orgCode);
            wQbdQualityKnow.setStatus( HAIR_DOWN_MAP.get( ZhiLiangConst.GROUP_ALREADY_SEND3));
            addAndupdate(wQbdQualityKnow);
        }
        return dao.addList(list);
    }

    /**
     *
     * @param queryFilter
     * @return
     */
    public List<WQbdQualityKnow> queryByCollectionList(QueryFilter queryFilter) {
      return   dao.queryByCollectionList(queryFilter);

    }
}
